package com.ophiux.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;

/**
 * 流控规则
 * 1.如何使用: https://github.com/alibaba/Sentinel/wiki/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8
 */
@RestController
public class SentinelController {
	
	@RequestMapping("/getOrder3")
	@SentinelResource(value = "getOrder3", blockHandler = "getOrderQpsException")
	public String getOrder3() {
		return "getOrder3接口，gateway整合sentinel、nacos持久化，连接控制台限流规则";
	}
	
	@RequestMapping("/getOrder4")
	@SentinelResource(value = "getOrder4", blockHandler = "getOrderQpsException")
	public String getOrder4() {
		return "getOrder4接口，gateway整合sentinel、nacos持久化，连接控制台限流规则";
	}
	
	/**
	 * 被限流后返回的提示
	 * @param e
	 * @return
	 */
	public String getOrderQpsException(BlockException e) {
	    e.printStackTrace();
	    return "该接口已经被限流啦!";
	}
}
